---
# Common configuration for the Module Build Service (MBS) pieces

- name: install needed packages
  package: name={{ item }} state=present
  with_items:
  - module-build-service
  - python-psycopg2
  - libsemanage-python
  - python-memcached
  notify:
  - restart apache
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: kill development configs
  file: path=/etc/fedmsg.d/{{ item }} state=absent
  with_items:
  - module_build_service.py
  - mbs-logging.py
  notify:
  - restart apache
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: copy app configuration
  template: >
    src=config.py dest=/etc/module-build-service/config.py
    owner=root group=fedmsg mode=0640
  notify:
  - restart apache
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: copy koji configuration
  template: >
    src=koji.conf dest=/etc/module-build-service/koji.conf
    owner=root group=fedmsg mode=0644
  notify:
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: copy fedmsg configuration
  template: >
    src=mbs-fedmsg.py dest=/etc/fedmsg.d/mbs-fedmsg.py
    owner=root group=fedmsg mode=0644
  notify:
  - restart apache
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: copy client secrets
  template: >
    src=client_secrets.json.{{env}} dest=/etc/module-build-service/client_secrets.json
    owner=root group=fedmsg mode=0640
  when: inventory_hostname.startswith('mbs-frontend')
  notify:
  - restart apache
  tags:
  - mbs
  - mbs/common

- name: create /etc/pdc.d directory
  file:
    path: /etc/pdc.d
    state: directory
    owner: root
    group: root
    mode: 0775

- name: copy pdc client config file
  copy: >
    src=fedora.json.{{env}} dest=/etc/pdc.d/fedora.json
    owner=root group=root mode=0644
  notify:
  - restart apache
  - restart fedmsg-hub
  tags:
  - mbs
  - mbs/common

- name: create /etc/module-build-service/default-modules directory
  file:
    path: /etc/module-build-service/default-modules
    state: directory
    owner: root
    group: root
    mode: 0775

- name: copy default modules to /etc/module-build-service/default-modules
  copy: src={{ item }} dest=/etc/module-build-service/default-modules
  with_fileglob:
  - default-modules.{{ env }}/*.yaml

- name: import default-modules
  command: /usr/bin/mbs-manager import_module /etc/module-build-service/default-modules/{{ item | basename }}
  with_fileglob:
  - default-modules.{{ env }}/*.yaml
  when: mbs_import_default_modules | default(True)


